/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package be.ugent.medirem.persistence.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

/**
 *
 * @author Thomas Roelens <thomas.roelens@ugent.be>
 */
@Entity
public class Prescription implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @ManyToOne
    private Medication medication;
    @ManyToOne
    private GeneralPractitioner gp;
    private double frequency;
    @OneToOne
    private Dosage dosage;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date startTime;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date endTime;
    private String remarks;
    @OneToMany
    private List<MedicationTask> tasks;

    public Prescription() {
    }

    public Prescription(Medication medication, GeneralPractitioner gp, double frequency, Dosage dosage, Date startTime, Date endTime, String remarks) {
        this.medication = medication;
        this.gp = gp;
        this.frequency = frequency;
        this.dosage = dosage;
        this.startTime = startTime;
        this.endTime = endTime;
        this.remarks = remarks;
    }
    
    public Dosage getDosage() {
        return dosage;
    }

    public void setDosage(Dosage dosage) {
        this.dosage = dosage;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public double getFrequency() {
        return frequency;
    }

    public void setFrequency(double frequency) {
        this.frequency = frequency;
    }

    public GeneralPractitioner getGp() {
        return gp;
    }

    public void setGp(GeneralPractitioner gp) {
        this.gp = gp;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Medication getMedication() {
        return medication;
    }

    public void setMedication(Medication medication) {
        this.medication = medication;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public List<MedicationTask> getTasks() {
        return tasks;
    }

    public void setTasks(List<MedicationTask> tasks) {
        this.tasks = tasks;
    }

    public void addTask(MedicationTask task) {
        tasks.add(task);
    }

    public boolean removeTask(MedicationTask task) {
        return tasks.remove(task);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Prescription)) {
            return false;
        }
        Prescription other = (Prescription) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "be.ugent.medirem.persistence.entity.Prescription[id=" + id + "]";
    }

}
